package com.xingkeduo.business.user.service;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.xingkeduo.dao.database.DatabaseAccessObject;
import com.xingkeduo.pojo.query.ConsumerFileQO;
import com.xingkeduo.pojo.query.ConsumerStyleQO;
import com.xingkeduo.pojo.table.ConsumerFileTO;
import com.xingkeduo.pojo.table.ConsumerStyleTO;
import com.xingkeduo.util.pojo.exception.DataException;
import com.xingkeduo.util.tool.CommonUtil;
import com.xingkeduo.util.tool.IdentityUtil;
import com.xingkeduo.util.tool.IdentityUtil.Worker;

/**
 * @Description:定位风格处理类
 * @Author:pantong
 * @Date 2019/4/28 18:29 
 **/
@Service
public class ConsumerStyleService {
    private static final String NAMESPACE = CommonUtil.formatNamespace(ConsumerStyleTO.class);
    @Resource(name = "mysqlUserMasterDao")
    private DatabaseAccessObject<ConsumerStyleTO, ConsumerStyleQO> dao;
    private static final String FILE_NAMESPACE = CommonUtil.formatNamespace(ConsumerFileTO.class);
    @Resource(name = "mysqlUserMasterDao")
    private DatabaseAccessObject<ConsumerFileTO, ConsumerFileQO> fileDao;

    
    //查询用户风格定位 
    public List<ConsumerStyleTO> selectConsumerStyleList(ConsumerStyleQO consumerStyleQO) throws Throwable {
        List<ConsumerStyleTO> consumerStyleList = dao.select(NAMESPACE, consumerStyleQO);
        if (!CommonUtil.isEmpty(consumerStyleList))
            return consumerStyleList;
        return null;
    }
    
    
    //更新用户风格定位
    public void updateConsumerStyle(ConsumerStyleTO consumerStyleTO) throws Throwable {
    	if (dao.update(NAMESPACE, consumerStyleTO) < 1)
			throw new DataException(DataException.Type.FAIL, "保存失败，请稍后重试！");
    }
    
    
    //新增用户风格定位
    public void addConsumerStyle(ConsumerStyleTO consumerStyleTO) throws Throwable {
    	consumerStyleTO.initId(IdentityUtil.nextId(Worker.USER));
    	consumerStyleTO.setUpdatedBy(consumerStyleTO.getConsumerId());
    	consumerStyleTO.setCreatedBy(consumerStyleTO.getConsumerId());
    	if (dao.insert(NAMESPACE, consumerStyleTO) < 1)
			throw new DataException(DataException.Type.FAIL, "保存失败，请稍后重试！");
    }
    
}
